<?php

class HelperUtil {
    
    public static function saveImage($savePath, $saveStream, $width, $height) {
        include_once(APP_URL.'protected/myUtil/ImageUtil.php');
        include_once(APP_URL.'protected/myUtil/FileUtil.php');
        $FileUtilObj = new FileUtil();
        if ($FileUtilObj->writeFile($savePath, $saveStream, true)) {
            $ImageUtilObj=new ImageUtil();
            $ImageUtilObj->open($savePath,false);
            $ImageUtilObj->resize_to($width, $height, 'force', array(255,255,255,0));
            if($ImageUtilObj->save_to($savePath)) {
                return true;
            } else{
                return false;
            }
        } else{
            return false;
        }
    }

    public static function sendSms($userPhone, $userVerifyCode) {
        include_once(APP_URL.'protected/myLib/cCPSMSSDK/CCPRestSmsSDK.php');
        
        // me
//         $accountSid= '8a48b55153eae51101541265d68d3de8';
//         $accountToken= 'b73c9481b6514b1589f0df5fa1408d97';
//         $appId='8a48b55153eae51101541269de3a3dff';
//         $serverIP='app.cloopen.com';
//         $serverPort='8883';
//         $softVersion='2013-12-26';
//         $to = $userPhone;
//         $datas = array($userVerifyCode, '10');
//         $tempId = 1;
        
        // test demo
        $accountSid= '8a48b55153eae51101541265d68d3de8';
        $accountToken= 'b73c9481b6514b1589f0df5fa1408d97';
        $appId='aaf98f8953ea8e8c0154126654f740ae';
        $serverIP='sandboxapp.cloopen.com';
        $serverPort='8883';
        $softVersion='2013-12-26';
        $to = $userPhone;
        $datas = array($userVerifyCode, '10');
        $tempId = 1;
        
        $rest = new REST($serverIP, $serverPort, $softVersion);
        $rest->setAccount($accountSid, $accountToken);
        $rest->setAppId($appId);
        $result = $rest->sendTemplateSMS($to, $datas, $tempId);
        
        if($result == NULL || $result->statusCode != 0) {
            return false;
        }
        return true;
    }
    
}
	